import type { AtNavBarProps } from 'taro-ui/types/nav-bar'
import type { NavBarProps } from './props'
import Taro from '@tarojs/taro'
import { THEME } from '@/constants/theme'

export function presetProps(leftType: NavBarProps['leftType'], props: AtNavBarProps) {
  if (!props.color) {
    props.color = THEME.primary
  }

  const leftTypes = {
    back: {
      leftIconType: 'chevron-left',
      onClickLeftIcon: () => Taro.navigateBack(),
    },
    home: {
      leftIconType: 'home',
      onClickLeftIcon: () => Taro.switchTab({ url: '/' }),
    },
  }

  return leftType && leftTypes[leftType]
    ? Object.assign(leftTypes[leftType], props)
    : props
}
